<?PHP if(! defined('BASEPATH')) exit('Sorry, no direct script allowed');

require_once FCPATH."application/libraries/smarty.class.php";

class Mysmarty extends Smarty
{
	
	function __construct()
	{
		parent::__construct();
		
		$this->tpl = new Smarty();
		
		$this->tpl->compile_check = TRUE;
		$this->tpl->force_compile = TRUE;
		
		$this->tpl->debugging = FALSE;
		$this->tpl->caching = TRUE;
		$this->tpl->cache_lifetime = 120;
		$this->tpl->left_delimiter = "{{";
		$this->tpl->right_delimiter = "}}";
		
		$this->tpl->template_dir = FCPATH."application/views/templates/";
		$this->tpl->compile_dir = FCPATH."application/views/templates_c/";
		$this->tpl->config_dir = FCPATH."application/libraries/configs/";
		
		$this->tpl->assign('FCPATH',FCPATH);
		$this->tpl->assign('APPPATH',APPPATH);
		$this->tpl->assign('BASEPATH',BASEPATH);
		
	}
	
	function set_delimiters($left = '{{', $right = '}}')
	{
		$this->tpl->left_delimiter($left);
		$this->tpl->right_delimiter($right); 
	}
	
	function assign($key, $value)
	{
		$this->tpl->assign($key, $value);
	}
	
	function display($template)
	{
		$this->tpl->display($template);
	}
	
	function fetch($template)
	{
		$this->tpl->fetch($template);
	}
	
	function render($doc = "index", $array = array())
	{
		foreach($array as $key => $val)
		{
			$this->tpl->assign($key, $val);
		}
		
		$this->tpl->display($doc.".tpl");
	}
	
	function display_document($doc, $array)
	{
		foreach($array as $key => $val)
		{
			$this->tpl->assign($key, $val);
		}
		
		$this->tpl->display($doc);
	}
	
	function layout($page = 'index', $array)
	{
		foreach($array as $key => $val)
		{
			$this->assign($key, $val);
		}
		
		$this->display($page.".tpl");
		exit();
	}
	
}


